﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Pap.Data;
using Pap.Web.Utils;

namespace Pap.Web.Modules.Reports.ViewModel
{
    /// <summary>
    /// 
    /// </summary>
    public class UsersTransactionsReportViewModel : IViewModel
    {
        /// <summary>
        /// 
        /// </summary>
        IReportRepository _ReportRepository;
        /// <summary>
        /// 
        /// </summary>
        IAdministrationRepository _adminRepository;

        /// <summary>
        /// Initializes a new instance of the <see cref="UsersTransactionsReportViewModel"/> class.
        /// </summary>
        /// <param name="reportRepository">The report repository.</param>
        /// <param name="adminRepository">The admin repository.</param>
        public UsersTransactionsReportViewModel(IReportRepository reportRepository, IAdministrationRepository adminRepository)
        {
            _ReportRepository = reportRepository;
            _adminRepository = adminRepository;

        }
        /// <summary>
        /// Gets the users transaction.
        /// </summary>
        /// <returns></returns>
        public DataSet GetUsersTransaction()
        {
            DataSet dsResult = new DataSet();
            DataTable dtResult = new DataTable();

            dtResult.Columns.Add("DisplayName", typeof(string));
            dtResult.Columns.Add("StepDisplayName", typeof(string));
            dtResult.Columns.Add("LoanNumber", typeof(int));
            dtResult.Columns.Add("CustomerName", typeof(string));
            dtResult.Columns.Add("ActionDisplayName", typeof(string));
            dtResult.Columns.Add("CreationDate", typeof(DateTime));
            dtResult.Columns.Add("CommitteeName", typeof(string));

            DataRow dr = null;
            List<IVUsersTransaction> lstUsersTransactions = _ReportRepository.FindUsersTransactions(u => true).ToList();
            foreach (VUsersTransaction userTransaction in lstUsersTransactions)
            {
                dr = dtResult.NewRow();
                dr["DisplayName"] = userTransaction.DisplayName;
                dr["StepDisplayName"] = userTransaction.StepDisplayName;
                dr["LoanNumber"] = userTransaction.LoanNumber;
                dr["CustomerName"] = userTransaction.CustomerName;
                dr["ActionDisplayName"] = userTransaction.ActionDisplayName;
                dr["CreationDate"] = userTransaction.CreationDate;
                dr["CommitteeName"] = userTransaction.CommitteeName;

                dtResult.Rows.Add(dr);
            }

            dsResult.Tables.Add(dtResult);

            return dsResult;
        }
        /// <summary>
        /// Gets all committees.
        /// </summary>
        /// <returns></returns>
        public IEnumerable<ICommittee> GetAllCommittees()
        {
            return _adminRepository.GetAllCommittees();
        }
    }
}